<?php

namespace Modules\Common\Util;


use Illuminate\Support\Facades\Validator as LaravelValidator;
use Modules\Common\Exceptions\Common\ValidationException;


class Validator
{
    public static function validate($data, $rules, $messages = [], $customAttributes = [])
    {
        $validator = LaravelValidator::make($data, $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            ValidationException::new()
                ->tellUser('参数校验不通过！', $validator->errors()->getMessages())
                ->logNotice('参数校验不通过！', ['errors' => $validator->errors()->getMessages(), 'data' => $data])
                ->throw();
        }
    }


    public static function validateWithoutThrow($data, $rules, $messages = [], $customAttributes = []){
        $validator = LaravelValidator::make($data, $rules, $messages, $customAttributes);
        return $validator->errors()->getMessages();
    }
}
